import {IconColor, IconType} from "@/components/IconFont/type";
import {reactive} from "vue";
import Buff from "@/modal/Buff";
import Score from "@/modal/Score";
import {ScoreType} from "@/components/ScorePanel/type";

const buff = reactive(Buff.getInstance());
const score = reactive(Score.getInstance());
export default abstract class Tool {
  readonly abstract name: IconType;
  readonly abstract chineseName: string;
  readonly abstract ripenStage: number;
  readonly abstract textDesc: string;
  public score: number = 0;
  private currentStage_: number = 0;

  readonly abstract featuresDesc: {
    titleIcon: { type: IconType, color?: IconColor },
    awardIcon?: { type: IconType, number?: number | string, color: IconColor, switch?: string },
    conditionIcon?: { type: IconType, number?: number | string, color: IconColor }[]
  };

  get currentStep() {return this.currentStage_;}

  get isRipen() {return this.currentStep === this.ripenStage;}

  get canUse() {return false}

  growUp() {
    if (!this.isRipen) {
      this.currentStage_++
    }
    return this;
  }

  getAward() {};
}

export class Glass extends Tool {
  readonly name: IconType = IconType.GLASS;
  readonly chineseName: string = "玻璃罐";
  readonly ripenStage: number = 1;
  readonly score: number = 1;
  readonly textDesc: string = "「黑莓」得「货物」";
  readonly featuresDesc = {
    titleIcon: {type: IconType.GLASS, color: IconColor.GOODS},
    awardIcon: {type: IconType.GOODS, color: IconColor.GOODS, number: 1, switch: "←"},
    conditionIcon: [{type: IconType.BLACKBERRY, color: IconColor.BLACKBERRY}]
  };

  getAward() {
    if (this.isRipen) {
      buff.extraGoodsForBlackberry(1);
      score.addScore(this.score, ScoreType.TOOL);
    }
    return this;
  }
}

export class Pie extends Tool {
  readonly name: IconType = IconType.PIE;
  readonly chineseName: string = "馅饼柜";
  readonly ripenStage: number = 2;
  readonly score: number = 3;
  readonly textDesc: string = `「苹果」/「桃子」得「货物」`;
  readonly featuresDesc = {
    titleIcon: {type: IconType.PIE, color: IconColor.GOODS},
    awardIcon: {type: IconType.GOODS, color: IconColor.GOODS, number: 1, switch: "←"},
    conditionIcon: [
      {type: IconType.APPLE, color: IconColor.APPLE},
      {type: IconType.PEACH, color: IconColor.PEACH}
    ]
  };

  getAward() {
    if (this.isRipen) {
      buff.extraGoodsForApple(1);
      buff.extraGoodsForPeach(1, IconType.TOOL);
      score.addScore(this.score, ScoreType.TOOL);
    }
    return this;
  }
}

export class Shovel extends Tool {
  readonly name: IconType = IconType.SHOVEL;
  readonly chineseName: string = "铲子";
  readonly ripenStage: number = 2;
  readonly score: number = 1;
  readonly textDesc: string = "花「堆肥」得「奖励行动」";
  readonly featuresDesc = {
    titleIcon: {type: IconType.SHOVEL, color: IconColor.FLOWER_PASSIVE},
    awardIcon: {type: IconType.BONUS, color: IconColor.FLOWER_PASSIVE, switch: "←"},
    conditionIcon: [{type: IconType.COMPOST, color: IconColor.COMPOST, number: "-3"}]
  };

  get canUse() {return this.isRipen}

  getAward() {
    if (this.isRipen) {
      score.addScore(this.score, ScoreType.TOOL);
      buff.extraBonusFromCompost();
    }
    return this;
  }
}

export class Salad extends Tool {
  readonly name: IconType = IconType.SALAD;
  readonly chineseName: string = "果盘";
  readonly ripenStage: number = 3;
  readonly textDesc: string = "每「种」不同水果得分数";
  readonly featuresDesc = {
    titleIcon: {type: IconType.SALAD, color: IconColor.SCORE},
    awardIcon: {type: IconType.SCORE, color: IconColor.SCORE, number: '1/4/7/10'}
  };

  getAward() {
    if (this.isRipen) {
      buff.extraScoreForFruitType();
    }
    return this;
  }
}

export class Barrels extends Tool {
  readonly name: IconType = IconType.BARRELS;
  readonly chineseName: string = "蓄雨桶";
  readonly ripenStage: number = 2;
  readonly score: number = 2;
  readonly textDesc: string = "「下雨」后「灌溉」菜畦";
  readonly featuresDesc = {
    titleIcon: {type: IconType.BARRELS, color: IconColor.IRRIGATE},
    awardIcon: {type: IconType.IRRIGATE, color: IconColor.IRRIGATE, switch: "←"},
    conditionIcon: [{type: IconType.RAIN, color: IconColor.IRRIGATE}]
  };

  getAward() {
    if (this.isRipen) {
      score.addScore(this.score, ScoreType.TOOL);
    }
    return this;
  }
}

export class Saucepan extends Tool {
  readonly name: IconType = IconType.SAUCEPAN;
  readonly chineseName: string = "炖锅";
  readonly ripenStage: number = 2;
  readonly textDesc: string = "每2份「豌豆」得1分";
  readonly featuresDesc = {
    titleIcon: {type: IconType.SAUCEPAN, color: IconColor.SCORE},
    awardIcon: {type: IconType.SCORE, color: IconColor.SCORE, number: 1, switch: "←"},
    conditionIcon: [{type: IconType.PEA, color: IconColor.IRRIGATE, number: 2}]
  };
}

export class Gorgeous extends Tool {
  readonly name: IconType = IconType.GORGEOUS;
  readonly chineseName: string = "华丽标签";
  readonly ripenStage: number = 3;
  readonly score: number = 2;
  readonly textDesc: string = "「乡间集市」得「花卉行动」";
  readonly featuresDesc = {
    titleIcon: {type: IconType.GORGEOUS, color: IconColor.FLOWER},
    awardIcon: {type: IconType.ACTION, color: IconColor.FLOWER, switch: "←"},
    conditionIcon: [{type: IconType.GORGEOUS, color: IconColor.FLOWER}]
  };

  getAward() {
    if (this.isRipen) {
      score.addScore(this.score, ScoreType.TOOL);
    }
    return this;
  }
}

export class Suit extends Tool {
  readonly name: IconType = IconType.SUIT;
  readonly chineseName: string = "蜂巢套装";
  readonly ripenStage: number = 3;
  readonly score: number = 2;
  readonly textDesc: string = "「番红花」得「蜂巢行动」";
  readonly featuresDesc = {
    titleIcon: {type: IconType.SUIT, color: IconColor.BEEHIVE},
    awardIcon: {type: IconType.BEEHIVE, color: IconColor.BEEHIVE, switch: "←"},
    conditionIcon: [{type: IconType.ACTION, color: IconColor.FLOWER, desc: "番红花"}]
  };

  getAward() {
    if (this.isRipen) {
      buff.extraBeehiveActionFromSaffron();
      score.addScore(this.score, ScoreType.TOOL);
    }
    return this;
  }
}

export class Fork extends Tool {
  readonly name: IconType = IconType.FORK;
  readonly chineseName: string = "干草叉";
  readonly ripenStage: number = 1;
  readonly score: number = 1;
  readonly textDesc: string = "「绣球花」得「堆肥」";
  readonly featuresDesc = {
    titleIcon: {type: IconType.FORK, color: IconColor.COMPOST},
    awardIcon: {type: IconType.COMPOST, color: IconColor.COMPOST, number: 1, switch: "←"},
    conditionIcon: [{type: IconType.ACTION, color: IconColor.FLOWER, desc: "绣球花"}]
  };

  getAward() {
    if (this.isRipen) {
      buff.extraCompostFromHydrangea();
      score.addScore(this.score, ScoreType.TOOL);
    }
    return this;
  }
}

export class Mower extends Tool {
  readonly name: IconType = IconType.MOWER;
  readonly chineseName: string = "割草机";
  readonly ripenStage: number = 3;
  readonly score: number = 6;
  readonly textDesc: string = "直接得分";
  readonly featuresDesc = {
    titleIcon: {type: IconType.MOWER, color: IconColor.SCORE},
    awardIcon: {type: IconType.SCORE, color: IconColor.SCORE}
  };

  getAward() {
    if (this.isRipen) {
      score.addScore(this.score, ScoreType.TOOL);
    }
    return this;
  }
}

export class Barrow extends Tool {
  readonly name: IconType = IconType.BARROW;
  readonly chineseName: string = "独轮车";
  readonly ripenStage: number = 2;
  readonly score: number = 3;
  readonly textDesc: string = "「工具棚」得「货物」";
  readonly featuresDesc = {
    titleIcon: {type: IconType.BARROW, color: IconColor.GOODS},
    awardIcon: {type: IconType.GOODS, color: IconColor.GOODS, number: 1, switch: "←"},
    conditionIcon: [{type: IconType.TOOL, color: IconColor.FERTILIZER}]
  };

  getAward() {
    if (this.isRipen) {
      buff.extraGoodsForTool(1);
      score.addScore(this.score, ScoreType.TOOL);
    }
    return this;
  }
}

export class Soil extends Tool {
  readonly name: IconType = IconType.SOIL;
  readonly chineseName: string = "护根土";
  readonly ripenStage: number = 1;
  readonly score: number = 1;
  readonly textDesc: string = "「区域行动」替换「花卉行动」";
  readonly featuresDesc = {
    titleIcon: {type: IconType.SOIL, color: IconColor.FLOWER},
    awardIcon: {type: IconType.ACTION, color: IconColor.FLOWER, switch: "="},
    conditionIcon: [
      {type: IconType.BEEHIVE, color: IconColor.BEEHIVE},
      {type: IconType.FRUIT, color: IconColor.IRRIGATE},
      {type: IconType.TOOL, color: IconColor.FERTILIZER}
    ]
  };

  get canUse() {return this.isRipen}

  getAward() {
    if (this.isRipen) {
      score.addScore(this.score, ScoreType.TOOL);
    }
    return this;
  }
}

export class Tractor extends Tool {
  readonly name: IconType = IconType.TRACTOR;
  readonly chineseName: string = "拖拉机";
  readonly ripenStage: number = 6;
  readonly score: number = 18;
  readonly textDesc: string = "直接得分";
  readonly featuresDesc = {
    titleIcon: {type: IconType.TRACTOR, color: IconColor.SCORE},
    awardIcon: {type: IconType.SCORE, color: IconColor.SCORE}
  };

  getAward() {
    if (this.isRipen) {
      score.addScore(this.score, ScoreType.TOOL);
    }
    return this;
  }
}

export class Graver extends Tool {
  readonly name: IconType = IconType.GRAVER;
  readonly chineseName: string = "南瓜刻刀";
  readonly ripenStage: number = 3;
  readonly textDesc: string = "「最长连续成熟南瓜」1个得1分";
  readonly featuresDesc = {
    titleIcon: {type: IconType.GRAVER, color: IconColor.SCORE},
    awardIcon: {type: IconType.SCORE, color: IconColor.SCORE, number: "n", switch: "←"},
    conditionIcon: [{type: IconType.PUMPKIN, color: IconColor.GOODS, number: "n"}]
  };

  getAward() {
    if (this.isRipen) {
      buff.extraScoreForPumpkin();
    }
    return this;
  }
}

export class Seeder extends Tool {
  readonly name: IconType = IconType.SEEDER;
  readonly chineseName: string = "播种机";
  readonly ripenStage: number = 4;
  readonly score: number = 2;
  readonly textDesc: string = "「种植作物数量」提高";
  readonly featuresDesc = {
    titleIcon: {type: IconType.SEEDER, color: IconColor.IRRIGATE},
    awardIcon: {type: IconType.FARM, color: IconColor.IRRIGATE, number: 3, switch: "↑"},
    conditionIcon: [{type: IconType.FARM, color: IconColor.IRRIGATE, number: 2}]
  };

  getAward() {
    if (this.isRipen) {
      score.addScore(this.score, ScoreType.TOOL);
    }
    return this;
  }
}